package com.lzx.utils;



import java.io.File;
import java.util.Date;

import com.oreilly.servlet.multipart.FileRenamePolicy;

/**
 * @author liangst
 * 
 * @CreateTime Sep 3, 2009 11:15:28 PM
 * 
 * @version 1.0
 */
public class RandomFileRenamePolicy implements FileRenamePolicy {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.oreilly.servlet.multipart.FileRenamePolicy#rename(java.io.File)
	 */
	public File rename(File file) {
		String body = "";
		String ext = "";
		int pot = file.getName().lastIndexOf(".");
		if (pot != -1) {
			body = (new Date()).getTime() + "";
			ext = file.getName().substring(pot);
		} else {
			body = (new Date()).getTime() + "";
			ext = "";
		}
		String newName = body + ext;
		file = new File(file.getParent(), newName);
		return file;
	}
}
